package com.demo.web.wx;

import com.demo.dto.BaseResult;
import com.demo.dto.ListResult;
import com.demo.dto.Pagination;
import com.demo.entity.Goods;
import com.demo.entity.Offer;
import com.demo.service.IGoodsService;
import com.demo.service.IOfferService;
import com.demo.vo.OfferVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/wx/offer")
public class OfferWxController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IOfferService depService;
    @Autowired
    private IGoodsService goodService;

    /**
     * 创建
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public BaseResult<Map> get(Offer arg) {
    	OfferVo service_res = depService.selectByPrimaryKey(arg.getId());
        Goods gds = goodService.selectByPrimaryKey(Integer.valueOf(service_res.getGoodsId()));
        Map map = new HashMap();
        map.put("goods",gds);
        map.put("offer",service_res);
        BaseResult<Map> res = new BaseResult<Map>(true, map);
        return res;
    }
    
    /***
     * 分页查询
     * @param arg
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/query", method = RequestMethod.GET)
    public ListResult<OfferVo> query(OfferVo arg) {
        List<OfferVo> list = depService.queryByPage(arg);
        int total = depService.queryCount(arg);
        arg.getPage();
        Pagination page = new Pagination(arg.getPage(), total, arg.getSize());
        ListResult<OfferVo> res = new ListResult(true, list);
        res.setPage(page);
        return res;
    }
}
